package com.example.week02.day2.adapters;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.week02.R;
import com.example.week02.day2.beans.MoreTypeBean;

import java.util.List;

//多种条目适配器
public class MoreTypeAdapter extends RecyclerView.Adapter {

    public static final int TYPE_FULL_IMAGE = 0;
    public static final int TYPE_LEFT_IMAGE = 1;
    public static final int TYPE_THREE_IMAGES = 2;


    private final List<MoreTypeBean> mData;

    public MoreTypeAdapter(List<MoreTypeBean> data) {
        this.mData = data;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        if(viewType == TYPE_FULL_IMAGE){
            view = View.inflate(parent.getContext(), R.layout.item_type_full_image,null);
            return new FullImageHolder(view);
        }else if(viewType == TYPE_LEFT_IMAGE){
            view = View.inflate(parent.getContext(), R.layout.item_type_left_image,null);
            return new LeftImageHolder(view);
        } else  {
            view = View.inflate(parent.getContext(), R.layout.item_type_three_image,null);
            return new ThreeImageHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        if(mData != null){
            return mData.size();
        }
        return 0;
    }

    //判断类型
    @Override
    public int getItemViewType(int position) {
        MoreTypeBean moreTypeBean = mData.get(position);
        if(moreTypeBean.type1 == 0){
            return TYPE_FULL_IMAGE;
        }else if(moreTypeBean.type1 == 1){
            return TYPE_LEFT_IMAGE;
        }else {
            return TYPE_THREE_IMAGES;
        }
    }

    private class FullImageHolder extends RecyclerView.ViewHolder{

        public FullImageHolder(@NonNull View itemView) {
            super(itemView);
        }
    }

    private class LeftImageHolder extends RecyclerView.ViewHolder{

        public LeftImageHolder(@NonNull View itemView) {
            super(itemView);
        }
    }

    private class ThreeImageHolder extends RecyclerView.ViewHolder{

        public ThreeImageHolder(@NonNull View itemView) {
            super(itemView);
        }
    }

}
